/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, { Component } from 'react'
import { Platform, StyleSheet, Text, View, Button, AlertIOS } from 'react-native'
import { createStackNavigator, createAppContainer } from 'react-navigation'

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  android:
    'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
})

class HomeScreen extends Component {
  static navigationOptions = {
    title: 'Welcome'
  }
  render () {
    const {navigate} = this.props.navigation
    return (
      <View>
        <Button title={'go to profile'} onPress={() => navigate('Profile', {name: 'Jane'})}/>
      </View>
    )
  }
}

class ProfileScreen extends Component {
  render () {
    return (
      <View>
        <Text>HAHAHA!</Text>
      </View>
    )
  }
}

const AppNavigator = createStackNavigator({
  Home: {screen: HomeScreen},
  Profile: {screen: ProfileScreen}
})

export default createAppContainer(AppNavigator)

//
// type Props = {};
// export default class App extends Component<Props> {
//   render () {
//     return (
//       <NavigatorIOS
//         ref={'nav'}
//         initialRoute={{
//           component: HomePage,
//           title: '主页',
//           rightButtonTitle: 'Add',
//           onRightButtonPress: () => {AlertIOS.alert('提示', '这是一个提示')},
//           leftButtonIcon:
//         }}
//         style={{ flex: 1 }}
//       />
//     )
//   }
// }

class HomePage extends Component {
  render () {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Welcome to React Native!</Text>
        <Text style={styles.instructions}>To get started, edit App.js</Text>
        <Text style={styles.instructions}>{instructions}</Text>
      </View>
    )
  }

}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
})
